package cn.iocoder.yudao.module.reading.controller.app.book.vo;

import cn.iocoder.yudao.module.reading.framework.vo.BaseUrlConvertVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 绘本详情 Response VO
 *
 * @author 芋道源码
 */
@Schema(description = "用户 APP - 绘本详情 Response VO")
@Data
@EqualsAndHashCode(callSuper = false)
public class PictureBookDetailRespVO extends BaseUrlConvertVO {

    @Schema(description = "绘本ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long id;

    @Schema(description = "绘本标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "At School")
    private String title;

    @Schema(description = "封面图片URL", example = "https://example.com/book1.jpg")
    private String cover;

    @Schema(description = "页数", requiredMode = Schema.RequiredMode.REQUIRED, example = "8")
    private Integer pages;

    @Schema(description = "所属绘本集ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
    private Long bookSetId;

    @Schema(description = "所属绘本集标题", example = "牛津树1级")
    private String bookSetTitle;

    @Schema(description = "排序顺序", example = "1")
    private Integer sortOrder;

    @Schema(description = "阅读状态")
    private ReadStatusVO readStatus;

    @Schema(description = "页面列表")
    private List<BookPageRespVO> pageList;

    @Schema(description = "绘本页面")
    @Data
    public static class BookPageRespVO {
        @Schema(description = "页面ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        private Long id;

        @Schema(description = "页码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
        private Integer pageNumber;

        @Schema(description = "页面图片URL", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://example.com/page1.jpg")
        private String imageUrl;

        @Schema(description = "图片宽度", example = "800")
        private Integer imageWidth;

        @Schema(description = "图片高度", example = "600")
        private Integer imageHeight;

        @Schema(description = "页面文字内容", example = "This is a school.")
        private String textContent;

        @Schema(description = "中文翻译内容", example = "这是一所学校。")
        private String chineseTranslation;

        @Schema(description = "文本语言类型", example = "english")
        private String textLanguage;

        @Schema(description = "官方音频URL", example = "https://example.com/audio1.mp3")
        private String officialAudioUrl;

        @Schema(description = "音频时长（秒）", example = "30")
        private Integer audioDuration;

        @Schema(description = "阅读难度", example = "easy")
        private String readingDifficulty;

        @Schema(description = "重点词汇列表", example = "[\"school\", \"children\"]")
        private List<String> keyWords;

        @Schema(description = "是否有用户录音", example = "false")
        private Boolean hasUserRecording;
    }

    @Schema(description = "阅读状态")
    @Data
    public static class ReadStatusVO {
        @Schema(description = "是否已读", example = "true")
        private Boolean isRead;

        @Schema(description = "阅读次数", example = "3")
        private Integer readCount;

        @Schema(description = "最后阅读时间", example = "2023-12-01 10:30:00")
        private String lastReadAt;

        @Schema(description = "阅读进度", example = "0.75")
        private Double readProgress;

        @Schema(description = "最后阅读页码", example = "5")
        private Integer lastPage;

        @Schema(description = "阅读时长（分钟）", example = "30")
        private Integer readingTime;
    }

    /**
     * 转换URL字段
     * 将相对路径转换为完整URL
     */
    @Override
    public void convertUrls() {
        this.cover = convertUrl(this.cover);

        // 转换页面列表中的URL
        if (this.pageList != null) {
            this.pageList.forEach(page -> {
                page.imageUrl = convertUrl(page.imageUrl);
                page.officialAudioUrl = convertUrl(page.officialAudioUrl);
            });
        }
    }
}
